﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace FastaTo4_3
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Usage: FastaTo4_3 <fasta file>");
                return;
            }
            try
            {
                string fastaFile = args[0];
                string fourThirdFile = ProperFileName(fastaFile);
                string res = Make4_3(fastaFile, fourThirdFile);
                Console.WriteLine(res);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadKey();
        }

        private static string Make4_3(string fastaFile, string fourThirdFile)
        {
            string res = "Success";

            if (!File.Exists(fastaFile))
            {
                return "File not found: " + fastaFile;
            }

            using (FileStream fs = new FileStream(fastaFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            using (TextReader faReader = new StreamReader(fs))
            {
                using (FileStream write = new FileStream(fourThirdFile, FileMode.Create))
                {
                }
            }

            return res;
        }

        private static string ProperFileName(string partName)
        {
            string currFolder = Path.GetDirectoryName(partName);

            string fileName = Path.GetFileName(partName);
            foreach (char c in System.IO.Path.GetInvalidFileNameChars())
            {
                fileName = fileName.Replace(c, '_');
            }
            fileName = Path.Combine(currFolder, fileName + ".hex.4_3");
            return fileName;
        }

    }
}
